/*
 * @Author: lc
 * @version: v1.2
 * @Date: 2021-10-27 10:46:37
 * @LastEditors: lc
 * @LastEditTime: 2021-10-27 13:38:32
 * @Descripttion: 路由配置
 */
import Vue from 'vue'
import VueRouter from 'vue-router'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css' // Progress 进度条样式

Vue.use(VueRouter)

const routes = [
  {
    path: '/redirect',
    children: [
      {
        path: '/redirect/:path(.*)',
        component: resolve => require(['@/views/redirect'], resolve)
      }
    ]
  },
  {
    path: '/',
    redirect: '/index'
  },
  {
    path: '/index',
    component: resolve => require(['@/views/index'], resolve),
    name: 'index',
    meta: { title: '首页' }
  },
  {
    path: '/table',
    component: resolve => require(['@/views/table'], resolve),
    name: 'table',
    meta: { title: '表格组件' }
  }
]

const router = new VueRouter({
  mode: 'history',
  routes
})

router.beforeEach((to, from, next) => {
  console.log('to', to)
  console.log('from', from)
  document.title = `${to.meta.title} | vue-text系统`
  NProgress.start()
  next()
})

router.afterEach(() => {
  NProgress.done()
})

export default router
